<?php

use yii\grid\GridView;
use yii\helpers\Html;
use yii\widgets\Breadcrumbs;

/* @var $this yii\web\View */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = '管理员信息';
$this->params['breadcrumbs'][] = ['label' => '设置', 'url' => ['/setting/user/index']];
$this->params['breadcrumbs'][] = $this->title;

GLOBAL $_permission_flags;
$_permission_flags = $permission_flags;

?>

<?= Breadcrumbs::widget([
    'homeLink' => ['label' => '医疗管理系统', 'url' => '#'],
    'links' => isset($this->params['breadcrumbs']) ? $this->params['breadcrumbs'] : [],
]) ?>

<div class="sample-patient-index">

    <div class="d-flex mb-3">
        <?= !empty($permission_flags['create_user']) ? Html::a('新建管理员', ['/setting/user/create'], ['class' => 'btn btn-success mr-3']) : '' ?>
        <?= Html::beginForm(['/site/logout'], 'post'); ?>
        <?= Html::submitButton('退出登录', ['class' => 'btn btn-danger']) ?>
        <?= Html::endForm(); ?>
    </div>

    <?= !empty($dataProvider) ? GridView::widget([
         'dataProvider' => $dataProvider,
         'columns' => [

             'user_id',
             'username',
             'crt_name',
             'crt_time',

             [
                 'class' => 'yii\grid\ActionColumn',
                 'buttons' =>[
                     'delete' => function($url, $model, $key) {
                         return Html::a('<span class="glyphicon glyphicon-trash"></span>', ['/setting/user/delete', 'id' => $key['user_id']], [
                             'data' => [
                                 'confirm' => 'Are you sure you want to delete this item?',
                                 'method' => 'post',
                             ],
                         ]);
                     },
                     'update' => function($url, $model, $key) {
                         GLOBAL $_permission_flags;
                         return !empty($_permission_flags['assign_permission']) ? Html::a('<span class="glyphicon glyphicon-pencil"></span>', '/setting/user/assign-permissions?id=' . $key['user_id']) : '';
                     }
                 ],
                 'template' => '{delete} {update}',
             ],

         ],
     ]) : ''; ?>

</div>


